<?php
session_start();

require_once("../database.include.php");

	$username=$_GET["username"];
				
    $sql = "SELECT `group_name`, `user_name` FROM `group_user` 
    WHERE `group_name` IN (SELECT `group_name` FROM `group_user` WHERE `user_name` = '" . $username . "')
    ORDER BY `group_name`, `user_name`";
    
    $stmt = $conn->prepare($sql);
	$stmt->execute();
	$count = $stmt->rowcount();
    
    if ($count > 0) {
    print "<table border='1'><tr><td>User Name</td><td>Group Name</td></tr>";
    foreach ($conn->query($sql) as $row) {
    	echo "<tr>";
        echo "<td>" . $row['user_name'] . "</td>";
        echo "<td>" . $row['group_name'] . "</td>";
        echo "</tr>";
    }
    print "</table>";
    } else {
    	echo "Why not invite a Privr member to your group! <a href='#' onclick='showInviteUser()'>Invite User to a Group</a><br/>";
    }
?>